package logic

import (
	"context"
	"fmt"
	"teatch/model/mysql"

	"teatch/teacherrpc/internal/svc"
	"teatch/teacherrpc/teacherrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 收藏删除
func (l *CollectDelLogic) CollectDel(in *teacherrpc.CollectDelRequest) (*teacherrpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line

	var data mysql.Collect
	mysql.DB.Where("id = ?", in.CollectId).First(&data)
	if data.ID == 0 {
		return nil, fmt.Errorf("该收藏不存在")
	}

	mysql.DB.Delete(&data, in.CollectId)

	return &teacherrpc.CollectDelResponse{}, nil
}
